//
//  JwExServiceController.m
//  JwPack
//
//  Created by 陈警卫 on 2024-09-06.
//

#import "JwExServiceController.h"
#import "JwExService.h"

@interface JwExServiceController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *datas;

@end

@implementation JwExServiceController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupView];
    [self setupData];
}

- (void)setupData {
    
    self.datas = @[
        @{@"name": @"下拉刷新Token", @"vc": @""},
        @{@"name": @"userInfo",     @"vc": @""},
    ].mutableCopy;
    
    [self.tableView reloadData];
    
    GV_JwLocalCenter_localBaseModelName = @"JwLocalModel";
    [JwLocalCenter shared];
    
    [JwHttpManager shared].baseUrl = @"https://ebike-api-dev.vinkacloud.com/";
    [JwHttpManager shared].basePoint = @"api";
    
    [self requestLogin];
}

- (void)setupView {
    self.tableView = [[UITableView alloc] initWithFrame:(CGRectZero) style:(UITableViewStylePlain)];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.backgroundColor = [UIColor clearColor];
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.top.offset(kJwScrNavBatBarHeight);
        make.bottom.offset(0);
    }];
    
    kJwWeak(self);
    [self.tableView jw_mj_headerWithRefreshingBlock:^(UIScrollView * _Nonnull scrollView) {
        [wself requestRefreshToken];
    }];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.datas.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *identifier = @"UITableViewCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:identifier];
    }
    
    cell.backgroundColor = [UIColor clearColor];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    NSDictionary *param = self.datas[indexPath.row];
    NSString *name = param[@"name"];
    cell.textLabel.text = name;
    cell.textLabel.textColor = [UIColor blackColor];
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 50;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    NSDictionary *param = self.datas[indexPath.row];
    NSString *name = param[@"name"];
    
    if ([name isEqualToString:@"userInfo"]) {
        [self requestUserInfo];
    }
}

- (void)requestLogin {
    [[[JwExService alloc] init] login_view:self.view userName:@"chenjw" password:@"123456" comple:^(JwLoginModel * _Nonnull loginModel, JwHttpConfig * _Nonnull config) {
        
    }];
}

- (void)requestRefreshToken {
    [[[JwExService alloc] init] refreshTokenTest_scrollView:self.tableView comple:^(JwHttpConfig * _Nonnull config) {
        
    }];
}

- (void)requestUserInfo {
    [[[JwExService alloc] init] userInfo_view:self.view comple:^(JwHttpConfig * _Nonnull config) {
        
    }];
    
    [[[JwExService alloc] init] userInfo_view:self.view comple:^(JwHttpConfig * _Nonnull config) {
        
    }];
    
    [[[JwExService alloc] init] userInfo_view:self.view comple:^(JwHttpConfig * _Nonnull config) {
        
    }];
}


@end
